package com.caochenlei.tree.huffman;

//哈夫曼树的结点类
class Node implements Comparable<Node> {
    public Byte data;      //存放结点数据
    public int weight;     //存放结点权重
    public Node left;      //指向左子结点
    public Node right;     //指向右子结点

    //结点类构造方法
    public Node(Byte data, int weight) {
        this.data = data;
        this.weight = weight;
    }

    //判断是否是叶子
    public boolean isLeaf() {
        return this.left == null && this.right == null;
    }

    @Override//比较方法
    public int compareTo(Node that) {
        return this.weight - that.weight;
    }

    @Override//打印对象
    public String toString() {
        String d = data == null ? "null" : new String(new byte[]{data});
        return "Node{data=" + d + ", weight=" + weight + "}";
    }
}
